package com.service.gmall.product.controller;

import com.service.gmall.common.result.Result;
import com.service.gmall.model.product.BaseSaleAttr;
import com.service.gmall.model.product.SpuSaleAttr;
import com.service.gmall.product.service.BaseSaleAttrService;
import com.service.gmall.product.service.SpuSaleAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author alpha
 * @className: BaseSaleAttrController
 * @date 2022/8/27 11:28
 * @Description
 */
@RestController
@RequestMapping("/admin/product")
public class BaseSaleAttrController {
    @Autowired
    BaseSaleAttrService baseSaleAttrService;
    @Autowired
    SpuSaleAttrService spuSaleAttrService;

    /**
     * @param
     * @description: 获取销售属性
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/27 11:29
     */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList() {
        List<BaseSaleAttr> list = baseSaleAttrService.list();
        return Result.ok(list);
    }

    //  /spuSaleAttrList/{spuId}

    /**
     * 根据spuId获取销售属性
     * @param spuId
     * @return
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result getSpuSaleAttrList(@PathVariable("spuId") Long spuId) {
        List<SpuSaleAttr> spuSaleAttrList = spuSaleAttrService.getSpuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }

}
